/**
 * 
 */
package com.tunan.lsj.idgenerator;

import java.beans.ConstructorProperties;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.tunan.config.MyBatisConfig;
@Component

public final class SequenceKeyFcatory {
	@Autowired
	private MyBatisConfig myBatisConfig;

	private static final ConcurrentMap<String, DaMengSequenceMaxValueIncrementer> sequenceMap = new ConcurrentHashMap<String, DaMengSequenceMaxValueIncrementer>();

	public long getNextValue(String sequenceName) {
		DaMengSequenceMaxValueIncrementer osi = sequenceMap.get(sequenceName);
		if (osi == null) {
			osi = new DaMengSequenceMaxValueIncrementer(myBatisConfig.primaryDataSource(), "toonan", sequenceName);
			sequenceMap.put(sequenceName, osi);
		}
		return osi.nextLongValue();
	}
}
